package com.juqimiao.raccoon.commodity.domain.support.extension;

import com.juqimiao.linn.exception.BasicError;
import com.juqimiao.linn.exception.BusinessException;
import com.juqimiao.linn.extension.Extension;
import com.juqimiao.raccoon.commodity.domain.category.CategoryGroup;
import com.juqimiao.raccoon.commodity.domain.support.repository.CategoryGroupEntityRepI;
import org.springframework.beans.factory.annotation.Autowired;

@Extension(Interface = CategoryGroupPolicyExtPt.class,
        BusinessId = "center-platform")
public class DefaultCategoryGroupPolicyExt implements CategoryGroupPolicyExtPt {

    private final CategoryGroupEntityRepI repository;

    @Autowired
    public DefaultCategoryGroupPolicyExt(CategoryGroupEntityRepI repository) {
        this.repository = repository;
    }

    @Override
    public boolean checkSameNamePolicy(CategoryGroup categorygroup) {
        boolean check = false;
        CategoryGroup result = repository.getByName(categorygroup.getName(),
                categorygroup.getGroupType(),
                categorygroup.getScenario());
        if (result != null) {
            check = categorygroup.getName().equals(result.getName());
        }
        return check;
    }

    @Override
    public boolean canUpdatePolicy(CategoryGroup group) {
        boolean check = false;
        if (group.getPolicy().checkPublish()) {
            check = true;
        }
        return check;
    }
}
